package com.study.service.db3.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.study.entity.db3.Customer;
import com.study.entity.db3.qo.CustomerQO;
import com.study.enumeration.DeletedEnum;
import com.study.mapper.db3.CustomerMapper;
import com.study.service.db3.ICustomerService;
import com.study.util.BaseUtils;

/**
 * 客户表 服务实现类
 * 
 * @author chenk
 *
 */
@Service
public class CustomerServiceImpl implements ICustomerService {

	@Autowired
	private CustomerMapper customerMapper;

	@Override
	public Page<Customer> queryCustomers(Map<String, Object> map) {
		// 应该封装成QO
		CustomerQO customer = BaseUtils.mapToEntity(map, CustomerQO.class);
		customer.setDeleted(Integer.valueOf(DeletedEnum.否.getCode()));
		return customerMapper.queryCustomers(customer);
	}

	@Override
	public void saveCustomer(Customer customer) {
		customerMapper.saveCustomer(customer);
	}

	@Override
	public Customer getById(Long id) {
		return customerMapper.getById(id);
	}

	@Override
	public void updateCustomer(Customer customer) {
		customerMapper.updateCustomer(customer);
	}

	@Override
	public void deleteById(Long id) {
		Map<String, Object> paramMap = new HashMap<>();
		// 逻辑删除标识(0、否 1、是)
		paramMap.put("deleted", "1");
		paramMap.put("customerId", id);
		customerMapper.deleteById(paramMap);
	}

}
